﻿using System;
using System.Text;
using System.Collections.Generic;
using Autodesk.AutoCAD.Geometry;


namespace TX_TOOLBOX
{



    /// <summary>
    ///==================================================================================================================================================
    /// 横梁的施工阶段输入的恒载：在腹板中心线处加，（纵向恒载-横梁自重-荷载铺装）÷ 腹板数； 横梁铺装加为均布力
    /// 横梁的汽车分布系数算法： 从纵向中读出反力最大值Nmax，  Nmax/车道数/车道折线系数/偏载系数1.15
    /// 横梁的人群分布系数算法： 从纵向中读出反力最大值（或加载一跨的人群反力-约值）Nmax',  Nmax'/人行道宽度， 注意人群集度输入1kN/m2,人行道宽度输入1m
    /// 
    /// Madis：不要加载车辆组了，有车辆就可以了，活载先要加载车道，
    ///                  ___
    /// 车道间距1.8表示 ↓ ↓ 两个力，用绿点表示
    /// 输入0 则合为1个力，也是对的。
    ///==================================================================================================================================================
    /// </summary>
    public class ColumnFlowerCal
    {
        internal ColumnFlower2 column = null;
        internal BaseChenTai ctBase = new BaseChenTai();
        public double PileH = 5000;           //--建模用的立柱长度--
        public bool IsOneColumn = true;


        public bool IsOutPutTendon = true;
        public bool IsOutPutSTAGE = true;
        public bool IsOutPutUse = true;


        public double ElementSegL = 500;
        public bool SupportNode = false;
        public double P1_M = 4.42;              //二期恒载--- 铺装的二期恒载

        public double ZT1 = 20;
        public double ZT2 = 20;
        public double H1 = 0;
        public double H2 = 0;
        public double T1_ADD = 0;
        public double T2_ADD = 0;
        public double T1_SUB = 0;
        public double T2_SUB = 0;

        public bool Vel_USER_VFACT = false;
        public double Vel_LSPAN = 30;
        public double Vel_VFACT1 = 0;
        public double Vel_VFACT2 = 0;

        public double ten_MZFact = 0.2;
        public double ten_PCFact = 0.015;
        public double ten_SCFact = 0.03;

        public bool IsRoadCenterAddNode = true;
        public bool IsArcDotAddNode = true;


        public StructFEM_DB CreateFEM_DB()
        {
            StructFEM_DB femDb = new StructFEM_DB();

            //femDb.IsOutPutTendon = this.IsOutPutTendon;
            //femDb.IsOutPutSTAGE = this.IsOutPutSTAGE;
            //femDb.IsOutPutUse = this.IsOutPutUse;
            femDb.IsOutTTemp = false;

            femDb.H1 = this.H1;
            femDb.H2 = this.H2;
            femDb.ZT1 = this.ZT1;
            femDb.ZT2 = this.ZT2;
            femDb.T1_ADD = this.T1_ADD;
            femDb.T2_ADD = this.T2_ADD;
            femDb.T1_SUB = this.T1_SUB;
            femDb.T2_SUB = this.T2_SUB;


            femDb.FACT_Vel = 0;
            femDb.FACT_MAN = 0;


            double ColumnH = column.dzH;




            ColumnFlowerBlockLM2 blockLM = column.GetBlockLM();
            ColumnFlowerBlockLM1 blockCM = column.GetBlockCM(IsOneColumn);

            List<TxPolyline> sideCurveLM = blockLM.GetStructSideLine();
            List<TxPolyline> sideCurveCM = blockCM.GetStructSideLine();

            double TopYMin = Math.Min(Math.Min(sideCurveLM[0].StartPoint.Y, sideCurveLM[1].StartPoint.Y), Math.Min(sideCurveLM[2].StartPoint.Y, sideCurveLM[3].StartPoint.Y));
            double DwnYMax = Math.Max(Math.Max(sideCurveLM[0].EndPoint.Y, sideCurveLM[1].EndPoint.Y), Math.Max(sideCurveLM[3].EndPoint.Y, sideCurveLM[3].EndPoint.Y));


            double columnChageH = Math.Max(blockLM.GetRealChangH_OutSide(), blockCM.GetRealChangH_OutSide());
            List<double> distSetUp = TX_Math.DesignNew.BJ(columnChageH, 250, TX_Math.DesignNew.BJType.ADJ_BACK);
            List<double> distSetDn = TX_Math.DesignNew.BJ(TopYMin - columnChageH - DwnYMax, 500, TX_Math.DesignNew.BJType.ADJ_BACK);
            List<double> distSegLenth = new List<double>();
            distSegLenth.AddRange(distSetUp);
            distSegLenth.AddRange(distSetDn);

            //List<double> distSegLenth = MTL_Math.DesignTool.DesignNew.BJ(TopYMin - DwnYMax, 500, MTL_Math.DesignTool.DesignNew.BJType.ADJ_BACK);
            List<double> columnPos = new List<double>();
            double tempZ = 0;
            for (int i = 0; i <= distSegLenth.Count; i++)
            {
                columnPos.Add(tempZ);
                if (i != distSegLenth.Count)
                {
                    tempZ -= distSegLenth[i];
                }
            }
            System.Diagnostics.Debug.Assert(Math.Abs(TX_Math.Math2.sum(distSegLenth) - (TopYMin - DwnYMax)) < 0.00001);


            //-------------立柱-----------
            columnPos.Add(-blockLM.dzHtw);
            columnPos.Add(-blockLM.dzHti);
            if (IsOneColumn == false)
            {
                columnPos.Add(-blockLM.xlH1 - blockLM.xlH2 * 0.5);
            }
            columnPos = TX_Math.Math2.Union(columnPos);
            columnPos.Sort();
            columnPos.Reverse();

            int XLNodeIndex1 = -1;
            Point3d columnPointPre = new Point3d(IsOneColumn ? 0 : ((-blockLM.Column2_WTopI * 0.5 - blockLM.Column2_WTopX * 0.5) * 0.001), TopYMin / 1000.0, 0);
            double ColumnLM_W0 = IsOneColumn ? blockLM.Column1_WTop : blockLM.Column2_WTopX;
            double ColumnCM_W0 = blockCM.ColumnYTop;
            StructFEM_DB.DbRectSection rectPre = new StructFEM_DB.DbRectSection(ColumnCM_W0, ColumnLM_W0);////矩形W--侧面宽，H---立面宽[不要反了]
            for (int i = 1; i < columnPos.Count; i++)
            {
                if (Math.Abs(columnPos[i] - (-blockLM.xlH1 - blockLM.xlH2 * 0.5)) < 0.00001)
                {
                    XLNodeIndex1 = i;
                }

                Point3d columnLM_OuterL = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[0], TopYMin + columnPos[i]);
                Point3d columnLM_OuterR = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[1], TopYMin + columnPos[i]);
                Point3d columnLM_InnerL = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[2], TopYMin + columnPos[i]);
                Point3d columnLM_InnerR = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[3], TopYMin + columnPos[i]);

                Point3d columnCM_OuterL = AcadAssist.GetPoint3dAtCurveY(sideCurveCM[0], TopYMin + columnPos[i]);
                Point3d columnCM_OuterR = AcadAssist.GetPoint3dAtCurveY(sideCurveCM[1], TopYMin + columnPos[i]);
                Point3d columnCM_InnerL = AcadAssist.GetPoint3dAtCurveY(sideCurveCM[2], TopYMin + columnPos[i]);
                Point3d columnCM_InnerR = AcadAssist.GetPoint3dAtCurveY(sideCurveCM[3], TopYMin + columnPos[i]);

                double ColumnCM_W = columnCM_OuterR.X - columnCM_OuterL.X;
                double ColumnLM_W = columnLM_OuterR.X - columnLM_OuterL.X;

                Point3d columnPointCur = new Point3d(0, (TopYMin + columnPos[i]) / 1000.0, 0);


                if (IsOneColumn == false)
                {
                    ColumnCM_W = columnCM_OuterR.X - columnCM_OuterL.X;////矩形W--侧面宽，H---立面宽[不要反了]
                    ColumnLM_W = columnLM_OuterR.X - columnLM_InnerR.X;////矩形W--侧面宽，H---立面宽[不要反了]
                    columnPointCur = new Point3d((columnLM_OuterL.X + ColumnLM_W * 0.5) * 0.001, columnPointCur.Y, 0);
                }

                StructFEM_DB.DbRectSection rectCur = new StructFEM_DB.DbRectSection(ColumnCM_W, ColumnLM_W);////矩形W--侧面宽，H---立面宽[不要反了]
                femDb.AddElement(i, i + 1, columnPointPre, columnPointCur, rectPre, rectCur, true);

                columnPointPre = columnPointCur;
                rectPre = rectCur;
            }

            int Column1ElementCount = femDb.elems.Count;
            if (IsOneColumn == false)
            {
                for (int i = 0; i < Column1ElementCount; i++)
                {
                    Point3d tempPnt1 = new Point3d(-femDb.elems[i].Pnt1.X, femDb.elems[i].Pnt1.Y, 0);
                    Point3d tempPnt2 = new Point3d(-femDb.elems[i].Pnt2.X, femDb.elems[i].Pnt2.Y, 0);
                    femDb.AddElement(Column1ElementCount + 2 + i, Column1ElementCount + 3 + i, tempPnt1, tempPnt2, femDb.elems[i].nodeSectL, femDb.elems[i].nodeSectR, true);
                }
            }

            if (IsOneColumn == false && XLNodeIndex1 != -1)
            {
                StructFEM_DB.DbRectSection xlSect = new StructFEM_DB.DbRectSection(column.xlW, blockLM.xlH2);

                int XLNodeIndex2 = Column1ElementCount + 1 + XLNodeIndex1;
                Point3d xlPointL = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[2], TopYMin - blockLM.xlH1 - blockLM.xlH2 * 0.5);
                Point3d xlPointR = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[3], TopYMin - blockLM.xlH1 - blockLM.xlH2 * 0.5);
                xlPointL = new Point3d(xlPointL.X / 1000.0, xlPointL.Y / 1000.0, 0);
                xlPointR = new Point3d(xlPointR.X / 1000.0, xlPointR.Y / 1000.0, 0);

                double xlLength = xlPointR.X - xlPointL.X;
                int xlSegCount = Math.Max(1, Convert.ToInt32(xlLength / 0.5));
                double xlSegLen = xlLength / xlSegCount;
                for (int i = 0; i < xlSegCount; i++)
                {
                    Point3d xlPnt1 = new Point3d(xlPointL.X + i * xlSegLen, xlPointL.Y, 0);
                    Point3d xlPnt2 = new Point3d(xlPointL.X + (i + 1) * xlSegLen, xlPointL.Y, 0);
                    int xlNodeL = (i == 0) ? XLNodeIndex1 : (Column1ElementCount * 2 + 2 + i);
                    int xlNodeR = (i == xlSegCount - 1) ? XLNodeIndex2 : (Column1ElementCount * 2 + 3 + i);
                    femDb.AddElement(xlNodeL, xlNodeR, xlPnt1, xlPnt2, xlSect, xlSect, true);
                }
            }

            //-------------承台-----------
            int BaseElementIndex = femDb.elems.Count + 1 + (IsOneColumn ? (femDb.elems.Count + 1) : 0);

            Point3d baseDownPoint1 = new Point3d(IsOneColumn ? columnPointPre.X : 0, columnPointPre.Y, 0);
            Point3d baseDownPoint2 = new Point3d(IsOneColumn ? columnPointPre.X : 0, columnPointPre.Y - ctBase.ctH / 1000.0, 0);
            StructFEM_DB.DbRectSection rectBase = new StructFEM_DB.DbRectSection(ctBase.ctY, ctBase.ctOneX);////矩形W--侧面宽，H---立面宽[不要反了]
            femDb.AddElement(BaseElementIndex, BaseElementIndex + 1, baseDownPoint1, baseDownPoint2, rectBase, rectBase, true);

            //-------把所有单元
            femDb.SetElementAllIsDeck(false);




            //-------------桩基[桥博不能把桩基建进去]-----------
            //StructFEM_DB.DbCircleSection pileSect = new StructFEM_DB.DbCircleSection(ctBase.PileD);
            //int PileElementIndex = femDb.elems.Count + 1;
            //List<Point3d> pileCenter = ctBase.GetPilePosition();
            //int nPileSegCount = Convert.ToInt32(PileH / 1000);
            //double PileSegLenth = PileH / nPileSegCount;

            //for (int i = 0; i < pileCenter.Count; i++)
            //{
            //    Point3d pilePnt1 = new Point3d(pileCenter[i].X, baseDownPoint.Y - i * PileSegLenth, 0);
            //    Point3d pilePnt2 = new Point3d(pileCenter[i].X, baseDownPoint.Y - (i + 1) * PileSegLenth, 0);
            //    femDb.AddElement(BaseElementIndex, BaseElementIndex + 1, pilePnt1, pilePnt2, true);
            //    femDb.AddSection(pileSect, pileSect);
            //}
            return femDb;
        }

        public StructFEM_Midas CreateFEM_Midas()
        {
            StructFEM_Midas femDb = new StructFEM_Midas();
            femDb.IsOutPutSectionOnly = false;
            femDb.IsOutPutStructOnly = true;

            femDb.H1 = this.H1;
            femDb.H2 = this.H2;
            femDb.ZT1 = this.ZT1;
            femDb.ZT2 = this.ZT2;
            femDb.T1_ADD = this.T1_ADD;
            femDb.T2_ADD = this.T2_ADD;
            femDb.T1_SUB = this.T1_SUB;
            femDb.T2_SUB = this.T2_SUB;

            double ColumnH = column.dzH;

            femDb.AddMaterial(StructFEM_Midas.Material.CreateMaterialCon(1, "C50"));


            ColumnFlowerBlockLM2 blockLM = column.GetBlockLM();
            ColumnFlowerBlockLM1 blockCM = column.GetBlockCM(IsOneColumn);

            List<TxPolyline> sideCurveLM = blockLM.GetStructSideLine();
            List<TxPolyline> sideCurveCM = blockCM.GetStructSideLine();

            double TopYMin = Math.Min(Math.Min(sideCurveLM[0].StartPoint.Y, sideCurveLM[1].StartPoint.Y), Math.Min(sideCurveLM[2].StartPoint.Y, sideCurveLM[3].StartPoint.Y));
            double DwnYMax = Math.Max(Math.Max(sideCurveLM[0].EndPoint.Y, sideCurveLM[1].EndPoint.Y), Math.Max(sideCurveLM[3].EndPoint.Y, sideCurveLM[3].EndPoint.Y));


            double columnChageH = Math.Max(blockLM.GetRealChangH_OutSide(), blockCM.GetRealChangH_OutSide());
            List<double> distSetUp = TX_Math.DesignNew.BJ(columnChageH, 250, TX_Math.DesignNew.BJType.ADJ_BACK);
            List<double> distSetDn = TX_Math.DesignNew.BJ(TopYMin - columnChageH - DwnYMax, 500, TX_Math.DesignNew.BJType.ADJ_BACK);
            List<double> distSegLenth = new List<double>();
            distSegLenth.AddRange(distSetUp);
            distSegLenth.AddRange(distSetDn);

            //List<double> distSegLenth = MTL_Math.DesignTool.DesignNew.BJ(TopYMin - DwnYMax, 500, MTL_Math.DesignTool.DesignNew.BJType.ADJ_BACK);
            List<double> columnPos = new List<double>();
            double tempZ = 0;
            for (int i = 0; i <= distSegLenth.Count; i++)
            {
                columnPos.Add(tempZ);
                if (i != distSegLenth.Count)
                {
                    tempZ -= distSegLenth[i];
                }
            }
            System.Diagnostics.Debug.Assert(Math.Abs(TX_Math.Math2.sum(distSegLenth) - (TopYMin - DwnYMax)) < 0.00001);


            //-------------立柱-----------
            columnPos.Add(-blockLM.dzHtw);
            columnPos.Add(-blockLM.dzHti);
            if (IsOneColumn == false)
            {
                columnPos.Add(-blockLM.xlH1 - blockLM.xlH2 * 0.5);
            }
            columnPos = TX_Math.Math2.Union(columnPos);
            columnPos.Sort();
            columnPos.Reverse();

            int XLNodeIndex1 = -1;
            Point3d columnPointPre = new Point3d(IsOneColumn ? 0 : ((-blockLM.Column2_WTopI * 0.5 - blockLM.Column2_WTopX * 0.5) * 0.001), 0, TopYMin / 1000.0);
            StructFEM_Midas.SectionMidasBase rectColumnSame = MidasSectCreator.CreateSectValue_RectSectMM(1, "1", blockCM.ColumnY, IsOneColumn ? blockLM.Column1_W : blockLM.Column2_WX, StructFEM_Midas.SectOffset.CC);////矩形W--侧面宽，H---立面宽[不要反了]

            double ColumnLM_W0 = IsOneColumn ? blockLM.Column1_WTop : blockLM.Column2_WTopX;
            double ColumnCM_W0 = blockCM.ColumnYTop;
            StructFEM_DB.DbRectSection rectPre = new StructFEM_DB.DbRectSection(ColumnLM_W0, ColumnCM_W0);  ////注意这里桥博和Midas是不同的，两者相反  ---[桥博 矩形W--立面宽，H---立面宽]
            femDb.AddNode(columnPointPre, columnPointPre);
            for (int i = 1; i < columnPos.Count; i++)
            {
                if (Math.Abs(columnPos[i] - (-blockLM.xlH1 - blockLM.xlH2 * 0.5)) < 0.00001)
                {
                    XLNodeIndex1 = i;
                }

                Point3d columnLM_OuterL = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[0], TopYMin + columnPos[i]);
                Point3d columnLM_OuterR = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[1], TopYMin + columnPos[i]);
                Point3d columnLM_InnerL = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[2], TopYMin + columnPos[i]);
                Point3d columnLM_InnerR = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[3], TopYMin + columnPos[i]);

                Point3d columnCM_OuterL = AcadAssist.GetPoint3dAtCurveY(sideCurveCM[0], TopYMin + columnPos[i]);
                Point3d columnCM_OuterR = AcadAssist.GetPoint3dAtCurveY(sideCurveCM[1], TopYMin + columnPos[i]);
                Point3d columnCM_InnerL = AcadAssist.GetPoint3dAtCurveY(sideCurveCM[2], TopYMin + columnPos[i]);
                Point3d columnCM_InnerR = AcadAssist.GetPoint3dAtCurveY(sideCurveCM[3], TopYMin + columnPos[i]);

                double ColumnCM_W = columnCM_OuterR.X - columnCM_OuterL.X;
                double ColumnLM_W = columnLM_OuterR.X - columnLM_OuterL.X;

                Point3d columnPointCur = new Point3d(0, 0, (TopYMin + columnPos[i]) / 1000.0);


                if (IsOneColumn == false)
                {
                    ColumnCM_W = columnCM_OuterR.X - columnCM_OuterL.X;////矩形W--侧面宽，H---立面宽[不要反了]
                    ColumnLM_W = columnLM_OuterR.X - columnLM_InnerR.X;////矩形W--侧面宽，H---立面宽[不要反了]
                    columnPointCur = new Point3d((columnLM_OuterL.X + ColumnLM_W * 0.5) * 0.001, 0, columnPointCur.Z);
                }

                StructFEM_DB.DbRectSection rectCur = new StructFEM_DB.DbRectSection(ColumnLM_W, ColumnCM_W);////矩形W--侧面宽，H---立面宽[不要反了]

                StructFEM_Midas.SectionMidasBase sectTap = MidasSectCreator.CreateSectValue_RectTaperedSectMM(i, i.ToString(), rectPre.Wsum, rectPre.H, rectCur.Wsum, rectCur.H, StructFEM_Midas.SectOffset.CC);
                femDb.AddSection(sectTap);
                femDb.AddNode(columnPointCur, columnPointCur);
                femDb.AddElement(i, i + 1, i);

                columnPointPre = columnPointCur;
                rectPre = rectCur;
            }


            int Column1NodeCount = femDb.nodes.Count;
            int Column1ElementCount = femDb.elems.Count;
            if (IsOneColumn == false)
            {
                for (int i = 0; i < Column1NodeCount; i++)
                {
                    Point3d tempPnt = new Point3d(-femDb.nodes[i].MidasPnt.X, femDb.nodes[i].MidasPnt.Y, femDb.nodes[i].MidasPnt.Z);
                    femDb.AddNode(tempPnt, tempPnt);
                }
                for (int i = 0; i < Column1ElementCount; i++)
                {
                    femDb.AddElement(Column1ElementCount + 2 + i, Column1ElementCount + 3 + i, femDb.elems[i].iPro);
                }
            }

            if (IsOneColumn == false && XLNodeIndex1 != -1)
            {
                int xlNodeIndex = femDb.nodes.Count + 1;
                int xlSectIndex = femDb.SectionCount + 1;
                StructFEM_Midas.SectionMidasBase xlSect = MidasSectCreator.CreateSectValue_RectSectMM(xlSectIndex, "系梁", column.xlW, blockLM.xlH2, StructFEM_Midas.SectOffset.CC);
                femDb.AddSection(xlSect);

                int XLNodeIndex2 = Column1ElementCount + 1 + XLNodeIndex1;
                Point3d xlPointL = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[2], TopYMin - blockLM.xlH1 - blockLM.xlH2 * 0.5);
                Point3d xlPointR = AcadAssist.GetPoint3dAtCurveY(sideCurveLM[3], TopYMin - blockLM.xlH1 - blockLM.xlH2 * 0.5);
                xlPointL = new Point3d(xlPointL.X / 1000.0, xlPointL.Y / 1000.0, 0);
                xlPointR = new Point3d(xlPointR.X / 1000.0, xlPointR.Y / 1000.0, 0);

                double xlLength = xlPointR.X - xlPointL.X;
                int xlSegCount = Math.Max(1, Convert.ToInt32(xlLength / 0.5));
                double xlSegLen = xlLength / xlSegCount;
                for (int i = 0; i < xlSegCount; i++)
                {
                    Point3d xlPnt1 = new Point3d(xlPointL.X + i * xlSegLen, 0, xlPointL.Y);
                    Point3d xlPnt2 = new Point3d(xlPointL.X + (i + 1) * xlSegLen, 0, xlPointL.Y);
                    femDb.AddNode(xlPnt1, xlPnt1);
                    if (i == xlSegCount - 1) femDb.AddNode(xlPnt2, xlPnt2);

                    femDb.AddElement(xlNodeIndex + i, xlNodeIndex + i + 1, xlSectIndex);
                }


                femDb.AddElasticLink(XLNodeIndex1, xlNodeIndex);
                femDb.AddElasticLink(XLNodeIndex2, femDb.nodes.Count);

            }
            return femDb;

            //-------------承台-----------
            //int BaseElementIndex = femDb.elems.Count + 1 + (IsOneColumn ? (femDb.elems.Count + 1) : 0);

            //Point3d baseDownPoint1 = new Point3d(IsOneColumn ? columnPointPre.X : 0, columnPointPre.Y, 0);
            //Point3d baseDownPoint2 = new Point3d(IsOneColumn ? columnPointPre.X : 0, columnPointPre.Y - ctBase.ctH / 1000.0, 0);
            //StructFEM_DB.DbRectSection rectBase = new StructFEM_DB.DbRectSection(ctBase.ctY, ctBase.ctX);////矩形W--侧面宽，H---立面宽[不要反了]
            //femDb.AddElement(BaseElementIndex, BaseElementIndex + 1, baseDownPoint1, baseDownPoint2, rectBase, rectBase, true);

            ////-------把所有单元
            //femDb.SetElementIsDeck(false);




            //-------------桩基[桥博不能把桩基建进去]-----------
            //StructFEM_DB.DbCircleSection pileSect = new StructFEM_DB.DbCircleSection(ctBase.PileD);
            //int PileElementIndex = femDb.elems.Count + 1;
            //List<Point3d> pileCenter = ctBase.GetPilePosition();
            //int nPileSegCount = Convert.ToInt32(PileH / 1000);
            //double PileSegLenth = PileH / nPileSegCount;

            //for (int i = 0; i < pileCenter.Count; i++)
            //{
            //    Point3d pilePnt1 = new Point3d(pileCenter[i].X, baseDownPoint.Y - i * PileSegLenth, 0);
            //    Point3d pilePnt2 = new Point3d(pileCenter[i].X, baseDownPoint.Y - (i + 1) * PileSegLenth, 0);
            //    femDb.AddElement(BaseElementIndex, BaseElementIndex + 1, pilePnt1, pilePnt2, true);
            //    femDb.AddSection(pileSect, pileSect);
            //}
            return femDb;

        }

        public void WriteFile(bool isMidis)
        {
            System.Windows.Forms.SaveFileDialog dlg = new System.Windows.Forms.SaveFileDialog();
            dlg.Filter = (isMidis) ? ("*.mct|*.mct") : ("*.dbs|*.dbs");
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                StringBuilder builder = new StringBuilder();
                if (isMidis == true)
                {
                    StructFEM_Midas fem_Midas = this.CreateFEM_Midas();
                    fem_Midas.WriteMidasFile(builder);
                }
                else
                {
                    StructFEM_DB fem_DB = this.CreateFEM_DB();
                    fem_DB.WriteDBFile(builder);
                }

                System.IO.TextWriter writer = new System.IO.StreamWriter(dlg.FileName, false, Encoding.Default);
                writer.Write(builder.ToString());
                writer.Close();
            }
        }
    }
}
